<?php if (!defined('THINK_PATH')) exit();?>
 <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap Admin</title>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" type="text/css" href="/TPproject/project/Public/Admin/Css/bootstrap.css">
    
    <link rel="stylesheet" type="text/css" href="/TPproject/project/Public/Admin/Css/theme.css">
    <link rel="stylesheet" href="/TPproject/project/Public/Admin/Css/font-awesome.css">

    <script src="/TPproject/project/Public/Admin/Js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="/TPproject/project/Public/Admin/Js/layer.js"></script>
    <script type="text/javascript" src="/TPproject/project/Public/Admin/static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="/TPproject/project/Public/Admin/static/h-ui.admin/js/H-ui.admin.js"></script>

    <script src="/TPproject/project/Public/Admin/Js/jquery.validation/jquery.validate.js" type="text/javascript"></script>


    <!-- Demo page code -->

    <style type="text/css">
        #line-chart {
            height:300px;
            width:800px;
            margin: 0px auto;
            margin-top: 1em;
        }
        .brand { font-family: georgia, serif; }
        .brand .first {
            color: #ccc;
            font-style: italic;
        }
        .brand .second {
            color: #fff;
            font-weight: bold;
        }
        .table>thead>tr>th
        {
          text-align: center;
        }
        .table>tbody>tr>td
        {
          text-align: center;
        }
    </style>



 
    <link rel="shortcut icon" href="/TPproject/project/Public/Admin/Img/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/TPproject/project/Public/Admin/Img/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/TPproject/project/Public/Admin/Img/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/TPproject/project/Public/Admin/Img/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="/TPproject/project/Public/Admin/Img/apple-touch-icon-57-precomposed.png">
  </head>
        
        

        <div class="container-fluid">
            <div class="row-fluid">
                    
<div class="btn-toolbar">
    <button class="btn btn-primary" id="submit"><i class="icon-save"></i> 提交</button>
    <!-- <a href="#myModal" data-toggle="modal" class="btn">删除</a> -->
  <div class="btn-group">
  </div>
</div>
<div class="well">
    
    <div id="myTabContent" class="tab-content">
      <div class="tab-pane active in" id="home">
    <form id="tab" method="post">
        <label>角色名称</label>
        <input type="text" value="<?php echo ($role["role_name"]); ?>" class="input-xlarge" id="role_name" name='role_name'>
        
        

        <label>角色权限</label>
        <?php if(is_array($list)): $i = 0; $__LIST__ = $list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><ul>
            <input type="checkbox" name="auths[]" class="fir" value="<?php echo ($vo["auth_id"]); ?>" <?php if($vo['auth_name'] == 首页): ?>disabled checked <?php elseif(in_array($vo['auth_id'],$arr_auth) and $vo['auth_name'] != 首页): ?> checked<?php endif; ?>><?php echo ($vo["auth_name"]); ?><br>
            <?php if(is_array($vo['child'])): $i = 0; $__LIST__ = $vo['child'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vol): $mod = ($i % 2 );++$i;?><ul>
                <input type="checkbox" name="auths[]" class="sec" value="<?php echo ($vol["auth_id"]); ?>" <?php if(in_array($vol['auth_id'],$arr_auth)): ?>checked<?php endif; ?>><?php echo ($vol["auth_name"]); ?>
                <?php if(is_array($vol['child'])): $i = 0; $__LIST__ = $vol['child'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$voli): $mod = ($i % 2 );++$i;?><input type="checkbox" name="auths[]" class="thir" value="<?php echo ($voli["auth_id"]); ?>" <?php if(in_array($voli['auth_id'],$arr_auth)): ?>checked<?php endif; ?>><?php echo ($voli["auth_name"]); endforeach; endif; else: echo "" ;endif; ?>
                <br>
              </ul><?php endforeach; endif; else: echo "" ;endif; ?>
          </ul>
          <br><?php endforeach; endif; else: echo "" ;endif; ?>

        <input type="hidden" name="role_id" value="<?php echo ($role["role_id"]); ?>">
        

        <button class="btn btn-primary" id="chkAll">全选</button>

        <button class="btn btn-primary" id="chkNone">全不选</button>

        <button class="btn btn-primary" id="invert">反选</button>

    </form>
      </div>
      
  </div>

</div>

<div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Delete Confirmation</h3>
  </div>
  <div class="modal-body">
    
    <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
    <button class="btn btn-danger" data-dismiss="modal">Delete</button>
  </div>
<!-- </div> -->
  <ul>
                    
    <input type="checkbox" name="auth_check" value="<?php echo $au['id'];?>" class='da' ><?php echo $au['authname'];?>
        
        <br>
        <?php if(isset($au['child'])){ foreach($au['child'] as $auc):?>
        <input type="checkbox" class='son' name="auth_check" value="<?php echo $auc['id'];?>" ><?php echo $auc['authname'];?>

        <?php endforeach ;}?>
        
        
      </br>
  </ul>


<script type="text/javascript">

  var chkAll = $("#chkAll");
  var chkNone = $("#chkNone");
  var invert = $("#invert");
  var check = $("input[type=checkbox]");
  var fir = $(".fir");
  var sec = $(".sec");
  var thir = $(".thir");


  //全选
  chkAll.click(function(){
    check.each(function(){
      $(this).attr('checked',true);
    })
    return false;
  })  

  //全不选
  chkNone.click(function(){
    check.each(function(){
      $(this).attr('checked',false);
    })
    $("input[value=1]").attr('checked',true);
    return false;
  })  
  //反选
  invert.click(function(){
    check.each(function(){
      var th = $(this).attr('checked');
      if(th){
        $(this).attr('checked',false);
      }else{
        $(this).attr('checked',true);
      }
    })
    $("input[value=1]").attr('checked',true);
    return false;
  })
  
  fir.click(function(){
    var th = $(this).attr('checked');
    if(th){
      $(this).siblings().children().attr('checked',true);
      // alert($(this)..val());
    }else{
      $(this).siblings().children().attr('checked',false);
    }
    
  })

  sec.click(function(){
    var th = $(this).attr('checked');
    if(th){
      $(this).parent().siblings().attr('checked',true);
      $(this).siblings().attr('checked',true);

    }else{
      $(this).siblings().attr('checked',false);
    }
  })

  thir.click(function(){
    var th = $(this).attr('checked');
    if(th){
      $(this).siblings().eq(0).attr('checked',true);
      $(this).parent().siblings().attr('checked',true);
    }
  })


  function role_name_blur(){
      var role_name = $('#role_name').val();
      if(role_name==''){
        layer.msg('角色名称必须！',{icon:2,time:1000});return false;
      }else{
        return true;
      }
  }

  


  $('#role_name').blur(function(){
      role_name_blur();
  })

 


  $("#submit").click(function(){
 

      //提交前确认信息无误
      if(role_name_blur()){
        
          $.post("",$("#tab").serialize(),function(msg){
              if(msg.code=='1'){
                layer.msg(msg.info,{icon:1,time:1000},function(index){
                  window.parent.location.reload();
                });

              }else{
                layer.msg(msg.info,{icon:2,time:1000});
                return false;
              }
          })
        
      }
      


      
  })
  
</script>